package xyz.hujf.tool.并发包原理解析.抽象同步队列;

import xyz.hujf.otherbase.lock.ReentrantLockTest;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Hujf
 * @title: AqsTeat
 * @date 2021-04-30 9:51
 * @description: TODO
 */
public class AqsTeat {
    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock = new ReentrantLock();
        Condition condition = lock.newCondition();

        new Thread(() -> {
            lock.lock();
            try {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("begin signal ");
                condition.signal();
                System.out.println("end signal ");
            } finally {
                lock.unlock();
            }
        }).start();
        lock.lock();
        try {
            System.out.println("begin wait");
            //在没有获得锁前调用wait方法 倒置异常
            condition.await();
            System.out.println("end wait");
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }



    }
}
